var qqmap = new (require("../../utils/qqmap-wx-jssdk.js"))({
  key: "SRLBZ-IMZ6J-SUIFA-FT724-N27WE-73BPK"
});
// pages/map/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keywords: '',
    searchList: '',
    userLocation: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },
  goSelAddr: function () {
    wx.navigateTo({
      url: '/pages/address/index',
    })
    wx.setStorageSync('fromWhere', '/pages/map/index')
  },
  changeKeywords: function(e) {
    this.setData({
      keywords: e.detail.value
    })
  },
  mapSearch: function(e) {
    var keywords = this.data.keywords
    if (!keywords) {
      return
    }
    var _this = this
    qqmap.getSuggestion({
      keyword: keywords,
      region: '深圳市',
      policy: 1,
      success: function (res) {
        _this.setData({
          searchList: res.data
        })
      },
      fail: function (e) {
      }
    });
  },
  selAddress: function(e) {
   var addr = e.currentTarget.dataset.address
    this.setData({
      searchList: ''
    })
    wx.setStorageSync('myAddress', addr)
    wx.reLaunch({
      url: '/pages/index/index',
    })
  },
  getCurAddress: function () {
    var e = this;
    wx.getLocation({
      type: "gcj02",
      success: function (t) {
        var s = t.latitude, a = t.longitude;
        wx.chooseLocation({
          latitude: s,
          longitude: a,
          scale: 28,
          success: function (res) {
            var addr = res.address
            wx.setStorageSync('myAddress', addr)
            setTimeout(function(){
              wx.reLaunch({
                url: '/pages/index/index',
              })
            },200)
          }
          
        });
      },
      fail: function(res) {
        
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getSetting()
  },
  getSetting: function () {
    var _this = this
    wx.getSetting({
      success: (data) => {
        var authLocation = true
        if (!data.authSetting['scope.userLocation']) {
          authLocation = false
        }
        _this.setData({
          userLocation: authLocation
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})